<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="开票公司" prop="billing_company">
        <el-input
          v-model="queryParams.billing_company"
          placeholder="请输入开票公司"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="结算单位" prop="settlement_unit">
        <el-input
          v-model="queryParams.settlement_unit"
          placeholder="请输入结算单位"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="账单类型" prop="bill_type">
        <el-input
          v-model="queryParams.bill_type"
          placeholder="请输入账单类型"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="业务类型" prop="business_type">
        <el-input
          v-model="queryParams.business_type"
          placeholder="请输入业务类型"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="币种" prop="currency">
        <el-input
          v-model="queryParams.currency"
          placeholder="请输入币种"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="账单号" prop="bill_num">
        <el-input
          v-model="queryParams.bill_num"
          placeholder="请输入账单号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="账单完成" prop="is_bill_ok">
        <el-select v-model="queryParams.is_bill_ok" placeholder="账单完成" clearable style="width: 100%">
          <el-option label="请选择" value="" />
          <el-option label="完成" value="1" />
          <el-option label="未完成" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="账单金额" prop="bill_money">
        <el-input
          v-model="queryParams.bill_money"
          placeholder="请输入账单金额"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="工作号" prop="job_number">
        <el-input
          v-model="queryParams.job_number"
          placeholder="请输入工作号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="通知开票" prop="is_notice_invoicing">
        <el-select v-model="queryParams.is_notice_invoicing" placeholder="通知开票" clearable style="width: 100%">
          <el-option label="请选择" value="" />
          <el-option label="已通知" value="1" />
          <el-option label="未通知" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="开票完成" prop="is_billing_completed">
        <el-select v-model="queryParams.is_billing_completed" placeholder="开票完成" clearable style="width: 100%">
          <el-option label="请选择" value="" />
          <el-option label="已完成" value="1" />
          <el-option label="未完成" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="发票号" prop="invoice_num">
        <el-input
          v-model="queryParams.invoice_num"
          placeholder="请输入发票号"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="账单标识" prop="bill_identification">
        <el-input
          v-model="queryParams.bill_identification"
          placeholder="请输入账单标识"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="created_at">
        <el-date-picker
          v-model="queryParams.created_at"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
<!--&lt;!&ndash;        <el-input-->
<!--          v-model="queryParams.created_at"-->
<!--          placeholder="请输入创建时间"-->
<!--          clearable-->
<!--          size="small"-->
<!--        />&ndash;&gt;-->
<!--&lt;!&ndash;        <div class="block">&ndash;&gt;-->
<!--          <span class="demonstration"> 开始日期时间 </span>-->
<!--          <el-date-picker-->
<!--            v-model="queryParams.created_at"-->
<!--            type="datetime"-->
<!--            placeholder="开始时间">-->
<!--          </el-date-picker>-->
<!--&lt;!&ndash;        </div>&ndash;&gt;-->
<!--&lt;!&ndash;        <div class="block">&ndash;&gt;-->
<!--          <span class="demonstration"> 结束日期时间 </span>-->
<!--          <el-date-picker-->
<!--            v-model="queryParams.created_at"-->
<!--            type="datetime"-->
<!--            placeholder="结束时间">-->
<!--          </el-date-picker>-->
<!--&lt;!&ndash;        </div>&ndash;&gt;-->
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column type="selection" align="center" width="50" />
      <el-table-column prop="job_number" label="工作号" align="center" width="200">
        <template v-slot="scope">
          <span style="color: #20a0ff;cursor:pointer" @click="see(scope.row)">{{ scope.row.job_number }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="bill_num" label="账单号" align="center" />
      <el-table-column prop="settlement_unit" label="结算单位" align="center" />
      <el-table-column prop="currency" label="币种" align="center" />
      <el-table-column prop="bill_money" label="账单金额" align="center" />
      <el-table-column prop="bill_type" label="账单类型" align="center" />
<!--      <el-table-column prop="remarks" label="备注" align="center" />-->
<!--      <el-table-column prop="billing_company" label="开票公司" align="center" />-->
      <el-table-column prop="is_bill_ok" label="账单完成" align="center" >
        <template v-slot="scope">
          <span v-if="scope.row.is_bill_ok === '1'">完成</span>
          <span v-if="scope.row.is_bill_ok === '2'">未完成</span>
        </template>
      </el-table-column>
<!--      <el-table-column prop="is_notice_invoicing" label="通知开票" align="center" >-->
<!--        <template v-slot="scope">-->
<!--          <span v-if="scope.row.is_bill_ok === '1'">已通知</span>-->
<!--          <span v-if="scope.row.is_bill_ok === '2'">未通知</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column prop="is_billing_completed" label="开票完成" align="center" >-->
<!--        <template v-slot="scope">-->
<!--          <span v-if="scope.row.is_bill_ok === '1'">已完成</span>-->
<!--          <span v-if="scope.row.is_bill_ok === '2'">未完成</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column prop="confirm_status" label="确认状态" align="center" width="200">
        <template v-slot="scope">
          <span v-if="scope.row.confirm_status === '1'">已确认</span>
          <span v-if="scope.row.confirm_status === '2'">未确认</span>
        </template>
<!--        <template v-slot="scope">-->
<!--          <el-switch-->
<!--            v-model="scope.row.confirm_status"-->
<!--            active-text="已确认"-->
<!--            inactive-text="未确认"-->
<!--            :active-value="'1'"-->
<!--            :inactive-value="'2'"-->
<!--            @change="disOrEnable($event,scope.row)"-->
<!--          />-->
<!--        </template>-->
      </el-table-column>
<!--      <el-table-column prop="invoice_num" label="发票号" align="center" />-->
      <el-table-column prop="created_at" label="开票日期" align="center" width="200"/>
<!--      <el-table-column prop="is_merge_reservation" label="合并保留" align="center" >-->
<!--        <template v-slot="scope">-->
<!--          <span v-if="scope.row.is_bill_ok === '1'">合并保留</span>-->
<!--          <span v-if="scope.row.is_bill_ok === '2'">不合并保留</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="详情" align="center" width="50">-->
<!--        <template v-slot="scope">-->
<!--          <span style="color: #20a0ff;cursor:pointer" @click="see(scope.row)">查看</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300" >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleEdit(scope.row)"
          >编辑
          </el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDel(scope.row)"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="warning"
            @click="prints(scope.row)"
          >打印
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
    <!-- 新增/修改 -->
    <AddEdit :open.sync="open" :title="title" :form="form" @getList="getList" />
    <!-- 详情 -->
    <Detail :opens.sync="opens" :title="title" :form="form" @getList="getList" />
    <!-- 打印 -->
    <Print :open-one.sync="openOne" :id="id" />
  </div>
</template>
<script>
import { billList , billDelete , billUpdate} from '@/api/settlement'
import AddEdit from './AddEdit'
import Detail from './Detail'
import Print from './Print'
export default {
  name: 'Index',
  components: {
    Print,
    AddEdit,
    Detail
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      open: false,
      opens: false,
      openOne: false,
      title: '',
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      form: {},
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        // billing_company: undefined,
        // settlement_unit: undefined
      },
      show: false,
      ids: [],
      confirm_status:2,
      id: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 状态
    disOrEnable(v, row) {
      const that = this
      const data = {}
      data.confirm_status = v
      data.id = row.id
      billUpdate(data).then(response => {
        that.$message.success(response.message)
        that.getList()
      })
    },
    /** 查询列表 */
    getList() {
      const that = this
      this.loading = true
      billList(this.queryParams).then(response => {
        console.log(response)
        if (response.code === 10000) {
          that.list = response.data
          that.total = response.count
          that.loading = false
        }
      })
    },
    /** 编辑按钮操作 */
    see(row) {
      this.form = row
      this.opens = true
      this.title = '详情'
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.form = {}
      this.open = true
      this.title = '添加'
    },
    /** 编辑按钮操作 */
    handleEdit(row) {
      this.form = row
      this.open = true
      this.title = '编辑'
    },
    /** 删除按钮操作 */
    handleDel(row) {
      console.log(row)
      const that = this
      that.$confirm('是否要删除？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        that.loading = true
        billDelete({ id: row.id.toString() }).then(response => {
          that.loading = false
          if (response.code === 10000) {
            that.$message.success(response.message)
            that.getList()
          } else {
            that.$message.error(response.message)
          }
        })
      }).catch(() => {
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        limit: 10,
        company_code: undefined,
        name_c: undefined
      }
      this.handleQuery()
    },
    /** 打印 */
    prints(row) {
      this.id = row.id
      this.openOne = true
    }
  }
}

</script>

